package com.bjpowernode.validator.controller;

import com.bjpowernode.validator.enums.ErrorCode;
import com.bjpowernode.validator.pojo.Department;
import com.bjpowernode.validator.server.DepartmentService;
import com.bjpowernode.validator.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ClassName:DepartmentController
 * Package:com.bjpowernode.validator.controller
 * Description: 描述信息
 *
 * @date:2022/3/19 9:56
 * @author:动力节点
 */
@RestController
@RequestMapping("/department")
//@Validated //对本类的方法，开启验证功能
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     *
     * 添加功能  addRoot Add
     * @RequestBoby 将json字符串转换为对象
     * @param department
     * @return
     */
    @PostMapping
    public ResultVO add(@RequestBody /*@Valid*/ Department department){
        /**
         * id           必须是 null
         * parentId     不能为 null,必须大于零
         * name         不能为空,长度必须大于零
         * createTime   肯定不是未来的时间
         */
        departmentService.add(department);
        return ResultVO.success();
    }


}
